package com.jdz.gxq.info.admin.economic.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.jdz.gxq.info.admin.economic.bo.Economic;
import com.jdz.gxq.info.admin.economic.form.AddEconomicForm;
import com.jdz.gxq.info.admin.economic.service.EconomicService;
import com.jdz.gxq.info.common.action.CommonAction;

public class AddEconomicAction extends CommonAction {

	private EconomicService economicService = null;
	 
	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {
		
		AddEconomicForm addEconomicFrom = (AddEconomicForm) form;
		
		Economic economic = addEconomicFrom.getEconomic();
		
		// 如果已经存在该企业的经济数据，则返回错误提示信息给页面
		if (economicService.getEconomicById(economic.getEnterpriseId()) != null) {
			ActionMessages messages = new ActionMessages();
			messages.add("economic.enterpriseName", new ActionMessage("error.economicExisted"));
			addErrors(request, messages);
			return mapping.getInputForward();
		}

		economic.setModifiedBy(getUserId(request));
		
		economicService.insertEconomic(economic);

		return mapping.findForward("success");
	}

	public void setEconomicService(EconomicService economicService) {
		this.economicService = economicService;
	}
}

